<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Rep\ModelNumberRep;
use Illuminate\Http\Request;

class ModelNumber extends Controller
{
    //型号管理
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new ModelNumberRep();
    }

    /**
     * 获取型号列表
     * @param Request $request
     */
    public function getModelNumberList(Request $request){
        $params = $request->all();
        $data = $this->rep->getModelNumberListRep($params);
        return re(0,$data,'success');
    }

    public function addModelNumber(Request $request){
        $params = $request->all();
        $data = $this->rep->addModelNumberRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    public function alertModelNumber(Request $request){
        $params = $request->all();
        $data = $this->rep->alertModelNumberRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }


    /**
     * 产品关联型号
     * @param Request $request
     */
    public function createModelNumber(Request $request){
        $params = $request->all();
        $data = $this->rep->createModelNumberRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 删除型号
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delModelNumber(Request $request){
        $params = $request->all();
        $data = $this->rep->delModelNumberRep($params);
        return re(0);
    }

    /**
     * 移除关联
     */
    public function delProductModelnumber(Request $request){
        $params = $request->all();
        $data = $this->rep->delProductModelnumberRep($params);
        return re(0);
    }


    /**
     * 批量添加型号
     * @param Request $request
     */
    public function batchAddModelNumber(Request $request){
        $params = $request->all();
        $data = $this->rep->batchAddModelNumberRep($params);
        return re($data['code']);
    }


    //获取型号产品列表
    public function getProductInfoByModelNumberId(Request $request){
        $model_number_id = $request->input('model_number_id');
        $modelid = $request->input('modelid');
        $data = $this->rep->getProductInfoByModelNumberIdRep($model_number_id,$modelid);
        return re(0,$data);
    }

    /**
     * 产品id获取型号列表
     */
    public function getModelNumberListByProduct(Request $request){
        $product_id = $request->input('product_id');
        $data = $this->rep->getModelNumberListByProductRep($product_id);
        return re(0,$data);
    }

    /**
     *根据型号id获取主色id
     */
    public function getColorByModelNumberId(Request $request){
        $model_number_id = $request->input('model_number_id');
        $data = $this->rep->getColorByModelNumberIdRep($model_number_id);
        return re(0,$data);
    }

    //型号-工种-员工关联
    public function setModelNumberUser(Request $request)
    {
        $params = $request->only(['param_data']);
        $data = $this->rep->setModelNumberUserRep($params);
        return re(0,$data);
    }

    public function getModelNumberUser(Request $request){
        $params = $request->only(['model_number_id','product_id']);
        $data = $this->rep->getModelNumberUserRep($params);
        return re(0,$data);
    }

    public function getUserListByModelNumberId(Request $request)
    {

        $params = $request->only(['model_number_id','job_type_id']);
        $data = $this->rep->getUserListByModelNumberIdRep($params);
        return re(0,$data);
    }

    /**
     * 获取产品单价
     * @param Request $request
     * @return void
     */
    public function getProductUnitPrice(Request $request){
        $params = $request->only(['model_number_id','product_id','specification_id']);
        $data = $this->rep->getProductUnitPriceRep($params);
        return re(0,$data,'success');
    }

    public function updateProductUnitPrice(Request $request){
        $params = $request->only(['model_number_id','product_id','specification_id','unit_price']);
        $data = $this->rep->updateProductUnitPriceRep($params);
        return re(0,$data);
    }

    /**
     * 产品-型号-规格 关联
     * @return ModelNumberRep
     */
    public function setModelNumberSpecification(Request $request)
    {
        $params = $request->only(['model_number_id','product_id','specification_ids']);
        $data = $this->rep->setModelNumberSpecificationRep($params);
        return re(0,$data);
    }



}
